﻿using MongoDB.Driver;
using Sustainalytics.ClientDW.Synchronization.SyncESGData.AbstractClassesAndInterfaces;
using Sustainalytics.Synchronization.Interface;
using Sustainalytics.ESG.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Sustainalytics.ClientDW.Synchronization.SyncESGData.RPCompanyESGComputationResultLogic
{
    public class RPCompanyESGComputationCommand : SyncEsgCommand<RPCompanyESGComputationResult>
    {
        private readonly IMongoCollection<RPCompanyESGComputationResult> rpCompanyEsgComputationResultCollection;

        public RPCompanyESGComputationCommand(IMongoCollection<RPCompanyESGComputationResult> rpCompanyEsgComputationResultCollection, ILogger logger) : base(logger)
        {
            this.rpCompanyEsgComputationResultCollection = rpCompanyEsgComputationResultCollection;
        }

        protected override async Task<DeleteResult> DeleteAssociatedRecordsAsync(IEnumerable<Guid> companiesIds, Guid? additionalDiscriminator = null)
        {
            return await rpCompanyEsgComputationResultCollection.DeleteManyAsync(x => companiesIds.Contains(x.Id)).ConfigureAwait(false);
        }

        protected override async Task InsertRecordsAsync(IEnumerable<RPCompanyESGComputationResult> entities)
        {
            await rpCompanyEsgComputationResultCollection.InsertManyAsync(entities);
        }
    }
}
